﻿using Orchard.Environment.Extensions;
using Orchard.Localization;
using Orchard.Tokens;
using System;

namespace Vitus.Utils.Providers.Tokens
{
    public class TextTokenProvider : ITokenProvider
    {
        public TextTokenProvider()
        {
            T = NullLocalizer.Instance;
        }

        public Localizer T { get; set; }

        public void Describe(DescribeContext context)
        {
            context.For("Text")
                .Token("ToLower", T("To Lowercase"), T("Converts the string to lowercase."), "Text")
                .Token("ToUpper", T("To Uppercase"), T("Converts the string to uppercase."), "Text");
        }

        public void Evaluate(EvaluateContext context)
        {
            context.For<String>("Text")
                .Token("ToLower", str => str.ToLowerInvariant())
                    .Chain("ToLower", "Text", str => str.ToLowerInvariant())
                .Token("ToUpper", str => str.ToUpperInvariant())
                    .Chain("ToLower", "Text", str => str.ToUpperInvariant())
                ;
        }
    }
}